package main

import (
	"goProject/pro1/Server2/Resp"
	"io/ioutil"
	"log"
	"net/rpc"
	"os"
	"time"
)

//===================== Server1 ==================================
type Args1 struct {
	B []byte
}

//响应内容
type Result1 struct {
	Re string
}

// ===================== Server2 =================================
type Args2 struct {
	url string
}

type Result2 struct {
	Re string
}

func main() {
	//远程调用图片转码服务
	go func() {
		client1, err := rpc.DialHTTP("tcp", "0.0.0.0:8080")
		if err != nil {
			log.Fatal(err)
		}
		f, err := os.Open("C:\\Users\\58294\\Pictures\\logo2.png")
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		b, err := ioutil.ReadAll(f)

		args1 := Args1{B: b}

		var res1 Result1

		err = client1.Call("Method.Picture", args1, &res1)
		if err != nil {
			log.Fatalf("error in Method", err)
		}
		log.Println(res1.Re)
	}()

	//远程调用请求网页内容
	go func() {
		client2, err := rpc.DialHTTP("tcp", "0.0.0.0:8081")
		if err != nil {
			log.Fatal(err)
		}
		//实例化请求参数
		args2 := &Resp.Args{Url: "https://www.baidu.com"}
		var res2 Result2
		err = client2.Call("Method.Resp", args2, &res2)
		if err != nil {
			log.Fatal(err)
		}
		log.Println(res2.Re)
	}()

	time.Sleep(time.Second * 2)
}
